package happywing.client;

import happywing.client.widget.Location;
import happywing.client.widget.LoginView;
import happywing.client.widget.PlatformView;

import java.util.HashMap;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.layout.client.Layout;
import com.google.gwt.layout.client.Layout.Layer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootLayoutPanel;


public class Stage {
	private final static Stage instance=new Stage();
	private HashMap<String, Composite> viewMap =new HashMap<String, Composite>();
	private LoginView loginView;
	private PlatformView platformView;
	private Location location;
	
	private String currentView="";
	
	public static Stage get() {
		return instance;
	}
	
	public void init(){
		loginView=new LoginView();
		platformView=new PlatformView();
		
		loginView.setStyleName("ztop");
		
		RootLayoutPanel.get().add(loginView);
		RootLayoutPanel.get().add(platformView);
		
		location=new Location(platformView.getBodyPanel());
	}
	
	public Location getLocation(){
		return this.location;
	}
	
	public void dropLoginView(){
		class Complete implements Layout.AnimationCallback {
			private String toView;
			@Override
			public void onAnimationComplete() {
				RootLayoutPanel.get().remove(loginView);
			}

			@Override
			public void onLayout(Layer layer, double progress) {
				
			}

		}
		RootLayoutPanel.get().forceLayout();
		RootLayoutPanel.get().setWidgetBottomHeight(loginView, -RootLayoutPanel.get().getOffsetHeight(), Unit.PX, RootLayoutPanel.get().getOffsetHeight(), Unit.PX);
		Layout.AnimationCallback complete=new Complete();
		RootLayoutPanel.get().animate(500,complete);
	}
	
	public void upLoginView(){
		loginView=new LoginView();
		loginView.setStyleName("ztop");
		RootLayoutPanel.get().add(loginView);
		RootLayoutPanel.get().setWidgetBottomHeight(loginView, -RootLayoutPanel.get().getOffsetHeight(), Unit.PX, RootLayoutPanel.get().getOffsetHeight(), Unit.PX);
		RootLayoutPanel.get().forceLayout();
		RootLayoutPanel.get().setWidgetTopBottom(loginView, 0, Unit.PX, 0, Unit.PX);
		RootLayoutPanel.get().animate(500);
	}
}

